<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Row polymorphism</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Row_polymorphism"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.math.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Row_polymorphism rootpage-Row_polymorphism skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Row polymorphism</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<style data-mw-deduplicate="TemplateStyles:r1251242444">
/* start https://en.wikipedia.org/ */
.mw-parser-output .ambox{border:1px solid #a2a9b1;border-left:10px solid #36c;background-color:#fbfbfb;box-sizing:border-box}.mw-parser-output .ambox+link+.ambox,.mw-parser-output .ambox+link+style+.ambox,.mw-parser-output .ambox+link+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+style+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+link+.ambox{margin-top:-1px}html body.mediawiki .mw-parser-output .ambox.mbox-small-left{margin:4px 1em 4px 0;overflow:hidden;width:238px;border-collapse:collapse;font-size:88%;line-height:1.25em}.mw-parser-output .ambox-speedy{border-left:10px solid #b32424;background-color:#fee7e6}.mw-parser-output .ambox-delete{border-left:10px solid #b32424}.mw-parser-output .ambox-content{border-left:10px solid #f28500}.mw-parser-output .ambox-style{border-left:10px solid #fc3}.mw-parser-output .ambox-move{border-left:10px solid #9932cc}.mw-parser-output .ambox-protection{border-left:10px solid #a2a9b1}.mw-parser-output .ambox .mbox-text{border:none;padding:0.25em 0.5em;width:100%}.mw-parser-output .ambox .mbox-image{border:none;padding:2px 0 2px 0.5em;text-align:center}.mw-parser-output .ambox .mbox-imageright{border:none;padding:2px 0.5em 2px 0;text-align:center}.mw-parser-output .ambox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ambox .mbox-image-div{width:52px}@media(min-width:720px){.mw-parser-output .ambox{margin:0 10%}}@media print{body.ns-0 .mw-parser-output .ambox{display:none!important}}
/* end https://en.wikipedia.org/ */
</style>
<p>In <a href="Programming_language" title="Programming language">programming language</a> <a href="Type_theory" title="Type theory">type theory</a>, <b>row polymorphism</b> is a kind of
<a href="Polymorphism_(computer_science)" title="Polymorphism (computer science)">polymorphism</a> that allows one to write programs that are polymorphic on row types such as
<a href="Record_(computer_science)" title="Record (computer science)">record types</a> and polymorphic variants.<sup id="cite_ref-1" class="reference"><a href="#cite_note-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> A row-polymorphic type system and proof of type inference was introduced by <a href="Mitchell_Wand" title="Mitchell Wand">Mitchell Wand</a>.<sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="Row-polymorphic_record_type_definition">Row-polymorphic record type definition</h2></div>
<p>The row-polymorphic record type defines a list of fields with their corresponding types, a list of missing fields, and a variable indicating the absence or presence of arbitrary additional fields. Both lists are optional, and the variable may be constrained. Specifically, the variable may be "empty", indicating that no additional fields may be present for the record.
</p><p>It may be written as <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \{\ell _{1}:T_{1},\dots ,\ell _{n}:T_{n},{\text{absent}}(f_{1}),\dots ,{\text{absent}}(f_{m}),\rho \}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mo fence="false" stretchy="false">{</mo>
<msub>
<mi>ℓ<!-- ℓ --></mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
<mo>:</mo>
<msub>
<mi>T</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
<mo>,</mo>
<mo>…<!-- … --></mo>
<mo>,</mo>
<msub>
<mi>ℓ<!-- ℓ --></mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>n</mi>
</mrow>
</msub>
<mo>:</mo>
<msub>
<mi>T</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>n</mi>
</mrow>
</msub>
<mo>,</mo>
<mrow class="MJX-TeXAtom-ORD">
<mtext>absent</mtext>
</mrow>
<mo stretchy="false">(</mo>
<msub>
<mi>f</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
</mrow>
</msub>
<mo stretchy="false">)</mo>
<mo>,</mo>
<mo>…<!-- … --></mo>
<mo>,</mo>
<mrow class="MJX-TeXAtom-ORD">
<mtext>absent</mtext>
</mrow>
<mo stretchy="false">(</mo>
<msub>
<mi>f</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>m</mi>
</mrow>
</msub>
<mo stretchy="false">)</mo>
<mo>,</mo>
<mi>ρ<!-- ρ --></mi>
<mo fence="false" stretchy="false">}</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \{\ell _{1}:T_{1},\dots ,\ell _{n}:T_{n},{\text{absent}}(f_{1}),\dots ,{\text{absent}}(f_{m}),\rho \}}</annotation>
</semantics>
</math></span><img src="./3054195cbae98df97ce8e3c3467ac4deea99437d.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:50.853ex; height:2.843ex;" alt="{\displaystyle \{\ell _{1}:T_{1},\dots ,\ell _{n}:T_{n},{\text{absent}}(f_{1}),\dots ,{\text{absent}}(f_{m}),\rho \}}" loading="lazy"></span>. This indicates a record type that has fields <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \ell _{i}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>ℓ<!-- ℓ --></mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>i</mi>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \ell _{i}}</annotation>
</semantics>
</math></span><img src="./bc03cf8f5f3927c6693a9ac9677685b08b29c106.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:1.769ex; height:2.509ex;" alt="{\displaystyle \ell _{i}}" loading="lazy"></span> with respective types of <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle T_{i}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>T</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>i</mi>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle T_{i}}</annotation>
</semantics>
</math></span><img src="./a8dd1c50cb9436474f83624c3f679ccf3eebbfef.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:2.157ex; height:2.509ex;" alt="{\displaystyle T_{i}}" loading="lazy"></span> (for <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle i=1\dots n}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>i</mi>
<mo>=</mo>
<mn>1</mn>
<mo>…<!-- … --></mo>
<mi>n</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle i=1\dots n}</annotation>
</semantics>
</math></span><img src="./3cabe81f4e3ffffc08230352d6af9e22b8fe7f5b.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:9.956ex; height:2.176ex;" alt="{\displaystyle i=1\dots n}" loading="lazy"></span>), and does not have any of the fields <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle f_{j}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>f</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>j</mi>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle f_{j}}</annotation>
</semantics>
</math></span><img src="./acc195ab3f9d65994b47774eb013601d09217aee.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -1.005ex; width:2.049ex; height:2.843ex;" alt="{\displaystyle f_{j}}" loading="lazy"></span> (for <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle j=1\dots m}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>j</mi>
<mo>=</mo>
<mn>1</mn>
<mo>…<!-- … --></mo>
<mi>m</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle j=1\dots m}</annotation>
</semantics>
</math></span><img src="./d13d46e739b4344c94b1c033c8801d82abe38d10.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; margin-left: -0.027ex; width:10.784ex; height:2.509ex;" alt="{\displaystyle j=1\dots m}" loading="lazy"></span>), while <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \rho }">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>ρ<!-- ρ --></mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \rho }</annotation>
</semantics>
</math></span><img src="./1f7d439671d1289b6a816e6af7a304be40608d64.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:1.202ex; height:2.176ex;" alt="{\displaystyle \rho }" loading="lazy"></span> expresses the fact the record may contain other fields than <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \ell _{i}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>ℓ<!-- ℓ --></mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>i</mi>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \ell _{i}}</annotation>
</semantics>
</math></span><img src="./bc03cf8f5f3927c6693a9ac9677685b08b29c106.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:1.769ex; height:2.509ex;" alt="{\displaystyle \ell _{i}}" loading="lazy"></span>.
</p><p>Row-polymorphic record types allow us to write programs that operate only on a section of a record. For example, one may define a function that performs some two-dimensional transformation that accepts a record with two or more coordinates, and returns an identical type:
</p>
<pre> <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\text{transform2d}}:\{x:{\text{Number}},y:{\text{Number}},\rho \}\to \{x:{\text{Number}},y:{\text{Number}},\rho \}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mtext>transform2d</mtext>
</mrow>
<mo>:</mo>
<mo fence="false" stretchy="false">{</mo>
<mi>x</mi>
<mo>:</mo>
<mrow class="MJX-TeXAtom-ORD">
<mtext>Number</mtext>
</mrow>
<mo>,</mo>
<mi>y</mi>
<mo>:</mo>
<mrow class="MJX-TeXAtom-ORD">
<mtext>Number</mtext>
</mrow>
<mo>,</mo>
<mi>ρ<!-- ρ --></mi>
<mo fence="false" stretchy="false">}</mo>
<mo stretchy="false">→<!-- → --></mo>
<mo fence="false" stretchy="false">{</mo>
<mi>x</mi>
<mo>:</mo>
<mrow class="MJX-TeXAtom-ORD">
<mtext>Number</mtext>
</mrow>
<mo>,</mo>
<mi>y</mi>
<mo>:</mo>
<mrow class="MJX-TeXAtom-ORD">
<mtext>Number</mtext>
</mrow>
<mo>,</mo>
<mi>ρ<!-- ρ --></mi>
<mo fence="false" stretchy="false">}</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle {\text{transform2d}}:\{x:{\text{Number}},y:{\text{Number}},\rho \}\to \{x:{\text{Number}},y:{\text{Number}},\rho \}}</annotation>
</semantics>
</math></span><img src="./571ad84e90937bc250e7ddc4e0ed9734724658db.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:74.656ex; height:2.843ex;" alt="{\displaystyle {\text{transform2d}}:\{x:{\text{Number}},y:{\text{Number}},\rho \}\to \{x:{\text{Number}},y:{\text{Number}},\rho \}}" loading="lazy"></span>
</pre>
<p>Thanks to row polymorphism, the function may perform two-dimensional transformation on a three-dimensional (in fact, <i>n</i>-dimensional) point, leaving the <i>z</i> coordinate (or any other coordinates) intact. In a more general sense, the function can perform on any record that contains the fields <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle x}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>x</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle x}</annotation>
</semantics>
</math></span><img src="./87f9e315fd7e2ba406057a97300593c4802b53e4.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.33ex; height:1.676ex;" alt="{\displaystyle x}" loading="lazy"></span> and <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle y}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>y</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle y}</annotation>
</semantics>
</math></span><img src="./b8a6208ec717213d4317e666f1ae872e00620a0d.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:1.155ex; height:2.009ex;" alt="{\displaystyle y}" loading="lazy"></span> with type <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\text{Number}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mtext>Number</mtext>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle {\text{Number}}}</annotation>
</semantics>
</math></span><img src="./482c183c1022295dc6eedfd4b68fcb80d23161e0.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:8.208ex; height:2.176ex;" alt="{\displaystyle {\text{Number}}}" loading="lazy"></span>. There is no loss of information: the type ensures that all the fields represented by the variable <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \rho }">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>ρ<!-- ρ --></mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \rho }</annotation>
</semantics>
</math></span><img src="./1f7d439671d1289b6a816e6af7a304be40608d64.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:1.202ex; height:2.176ex;" alt="{\displaystyle \rho }" loading="lazy"></span> are present in the return type. In contrast, the type definition <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \{x:{\text{Number}},y:{\text{Number}},\mathbf {empty} \}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mo fence="false" stretchy="false">{</mo>
<mi>x</mi>
<mo>:</mo>
<mrow class="MJX-TeXAtom-ORD">
<mtext>Number</mtext>
</mrow>
<mo>,</mo>
<mi>y</mi>
<mo>:</mo>
<mrow class="MJX-TeXAtom-ORD">
<mtext>Number</mtext>
</mrow>
<mo>,</mo>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="bold">e</mi>
<mi mathvariant="bold">m</mi>
<mi mathvariant="bold">p</mi>
<mi mathvariant="bold">t</mi>
<mi mathvariant="bold">y</mi>
</mrow>
<mo fence="false" stretchy="false">}</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \{x:{\text{Number}},y:{\text{Number}},\mathbf {empty} \}}</annotation>
</semantics>
</math></span><img src="./9ff4f8f737a7f6610fdc19fdc04cf70bf4c14ec7.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:34.555ex; height:2.843ex;" alt="{\displaystyle \{x:{\text{Number}},y:{\text{Number}},\mathbf {empty} \}}" loading="lazy"></span> expresses the fact that a record of that type has exactly the <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle x}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>x</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle x}</annotation>
</semantics>
</math></span><img src="./87f9e315fd7e2ba406057a97300593c4802b53e4.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.33ex; height:1.676ex;" alt="{\displaystyle x}" loading="lazy"></span> and <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle y}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>y</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle y}</annotation>
</semantics>
</math></span><img src="./b8a6208ec717213d4317e666f1ae872e00620a0d.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:1.155ex; height:2.009ex;" alt="{\displaystyle y}" loading="lazy"></span> fields and nothing else. In this case, a classic record type is obtained.
</p>
<div class="mw-heading mw-heading2"><h2 id="Typing_operations_on_records">Typing operations on records</h2></div>
<p>The record operations of selecting a field <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle r.\ell }">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>r</mi>
<mo>.</mo>
<mi>ℓ<!-- ℓ --></mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle r.\ell }</annotation>
</semantics>
</math></span><img src="./5159e95ca3037ef265f85e7055819ce9fd9a1b6f.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:3.052ex; height:2.176ex;" alt="{\displaystyle r.\ell }" loading="lazy"></span>, adding a field <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle r[\ell :=e]}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>r</mi>
<mo stretchy="false">[</mo>
<mi>ℓ<!-- ℓ --></mi>
<mo>:=</mo>
<mi>e</mi>
<mo stretchy="false">]</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle r[\ell :=e]}</annotation>
</semantics>
</math></span><img src="./d553ee324151861fa3dbcde64a3bcd5c3dcb48e6.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:8.141ex; height:2.843ex;" alt="{\displaystyle r[\ell :=e]}" loading="lazy"></span>, and removing a field <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle r\backslash \ell }">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>r</mi>
<mi class="MJX-variant" mathvariant="normal">∖<!-- ∖ --></mi>
<mi>ℓ<!-- ℓ --></mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle r\backslash \ell }</annotation>
</semantics>
</math></span><img src="./73dbcb9f9fa86bb61a2373cd78dfff34036057b2.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:3.181ex; height:2.843ex;" alt="{\displaystyle r\backslash \ell }" loading="lazy"></span> can be given row-polymorphic types.
</p><p><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \mathrm {select_{\ell }} =\lambda r.(r.\ell )\;:\;\{\ell :T,\rho \}\rightarrow T}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="normal">s</mi>
<mi mathvariant="normal">e</mi>
<mi mathvariant="normal">l</mi>
<mi mathvariant="normal">e</mi>
<mi mathvariant="normal">c</mi>
<msub>
<mi mathvariant="normal">t</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>ℓ<!-- ℓ --></mi>
</mrow>
</msub>
</mrow>
<mo>=</mo>
<mi>λ<!-- λ --></mi>
<mi>r</mi>
<mo>.</mo>
<mo stretchy="false">(</mo>
<mi>r</mi>
<mo>.</mo>
<mi>ℓ<!-- ℓ --></mi>
<mo stretchy="false">)</mo>
<mspace width="thickmathspace"></mspace>
<mo>:</mo>
<mspace width="thickmathspace"></mspace>
<mo fence="false" stretchy="false">{</mo>
<mi>ℓ<!-- ℓ --></mi>
<mo>:</mo>
<mi>T</mi>
<mo>,</mo>
<mi>ρ<!-- ρ --></mi>
<mo fence="false" stretchy="false">}</mo>
<mo stretchy="false">→<!-- → --></mo>
<mi>T</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \mathrm {select_{\ell }} =\lambda r.(r.\ell )\;:\;\{\ell :T,\rho \}\rightarrow T}</annotation>
</semantics>
</math></span><img src="./230a656d810bdc6a5e6b479dc63c030895296d83.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:35.462ex; height:2.843ex;" alt="{\displaystyle \mathrm {select_{\ell }} =\lambda r.(r.\ell )\;:\;\{\ell :T,\rho \}\rightarrow T}" loading="lazy"></span>
</p><p><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \mathrm {add_{\ell }} =\lambda r.\lambda e.r[\ell :=e]\;:\;\{\mathrm {absent} (\ell ),\rho \}\rightarrow T\rightarrow \{\ell :T,\rho \}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="normal">a</mi>
<mi mathvariant="normal">d</mi>
<msub>
<mi mathvariant="normal">d</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>ℓ<!-- ℓ --></mi>
</mrow>
</msub>
</mrow>
<mo>=</mo>
<mi>λ<!-- λ --></mi>
<mi>r</mi>
<mo>.</mo>
<mi>λ<!-- λ --></mi>
<mi>e</mi>
<mo>.</mo>
<mi>r</mi>
<mo stretchy="false">[</mo>
<mi>ℓ<!-- ℓ --></mi>
<mo>:=</mo>
<mi>e</mi>
<mo stretchy="false">]</mo>
<mspace width="thickmathspace"></mspace>
<mo>:</mo>
<mspace width="thickmathspace"></mspace>
<mo fence="false" stretchy="false">{</mo>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="normal">a</mi>
<mi mathvariant="normal">b</mi>
<mi mathvariant="normal">s</mi>
<mi mathvariant="normal">e</mi>
<mi mathvariant="normal">n</mi>
<mi mathvariant="normal">t</mi>
</mrow>
<mo stretchy="false">(</mo>
<mi>ℓ<!-- ℓ --></mi>
<mo stretchy="false">)</mo>
<mo>,</mo>
<mi>ρ<!-- ρ --></mi>
<mo fence="false" stretchy="false">}</mo>
<mo stretchy="false">→<!-- → --></mo>
<mi>T</mi>
<mo stretchy="false">→<!-- → --></mo>
<mo fence="false" stretchy="false">{</mo>
<mi>ℓ<!-- ℓ --></mi>
<mo>:</mo>
<mi>T</mi>
<mo>,</mo>
<mi>ρ<!-- ρ --></mi>
<mo fence="false" stretchy="false">}</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \mathrm {add_{\ell }} =\lambda r.\lambda e.r[\ell :=e]\;:\;\{\mathrm {absent} (\ell ),\rho \}\rightarrow T\rightarrow \{\ell :T,\rho \}}</annotation>
</semantics>
</math></span><img src="./dc468e3a9450b5011093f021206ee7a97f1163de.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:57.952ex; height:2.843ex;" alt="{\displaystyle \mathrm {add_{\ell }} =\lambda r.\lambda e.r[\ell :=e]\;:\;\{\mathrm {absent} (\ell ),\rho \}\rightarrow T\rightarrow \{\ell :T,\rho \}}" loading="lazy"></span>
</p><p><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \mathrm {remove_{\ell }} =\lambda r.r\backslash \ell \;:\;\{\ell :T,\rho \}\rightarrow \{\mathrm {absent} (\ell ),\rho \}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="normal">r</mi>
<mi mathvariant="normal">e</mi>
<mi mathvariant="normal">m</mi>
<mi mathvariant="normal">o</mi>
<mi mathvariant="normal">v</mi>
<msub>
<mi mathvariant="normal">e</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>ℓ<!-- ℓ --></mi>
</mrow>
</msub>
</mrow>
<mo>=</mo>
<mi>λ<!-- λ --></mi>
<mi>r</mi>
<mo>.</mo>
<mi>r</mi>
<mi class="MJX-variant" mathvariant="normal">∖<!-- ∖ --></mi>
<mi>ℓ<!-- ℓ --></mi>
<mspace width="thickmathspace"></mspace>
<mo>:</mo>
<mspace width="thickmathspace"></mspace>
<mo fence="false" stretchy="false">{</mo>
<mi>ℓ<!-- ℓ --></mi>
<mo>:</mo>
<mi>T</mi>
<mo>,</mo>
<mi>ρ<!-- ρ --></mi>
<mo fence="false" stretchy="false">}</mo>
<mo stretchy="false">→<!-- → --></mo>
<mo fence="false" stretchy="false">{</mo>
<mrow class="MJX-TeXAtom-ORD">
<mi mathvariant="normal">a</mi>
<mi mathvariant="normal">b</mi>
<mi mathvariant="normal">s</mi>
<mi mathvariant="normal">e</mi>
<mi mathvariant="normal">n</mi>
<mi mathvariant="normal">t</mi>
</mrow>
<mo stretchy="false">(</mo>
<mi>ℓ<!-- ℓ --></mi>
<mo stretchy="false">)</mo>
<mo>,</mo>
<mi>ρ<!-- ρ --></mi>
<mo fence="false" stretchy="false">}</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \mathrm {remove_{\ell }} =\lambda r.r\backslash \ell \;:\;\{\ell :T,\rho \}\rightarrow \{\mathrm {absent} (\ell ),\rho \}}</annotation>
</semantics>
</math></span><img src="./067523cda7ddf0f2d60d4800ab2ea647b187ad73.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:47.823ex; height:2.843ex;" alt="{\displaystyle \mathrm {remove_{\ell }} =\lambda r.r\backslash \ell \;:\;\{\ell :T,\rho \}\rightarrow \{\mathrm {absent} (\ell ),\rho \}}" loading="lazy"></span>
</p>
<div class="mw-heading mw-heading2"><h2 id="Notes">Notes</h2></div>
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-1">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */
.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}
/* end https://en.wikipedia.org/ */
</style><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://v2.ocaml.org/manual/polyvariant.html">"OCaml - Polymorphic variants"</a>. <i>v2.ocaml.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2022-12-03</span></span>.</cite></span>
</li>
<li id="cite_note-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-2">^</a></b></span> <span class="reference-text">
<cite id="CITEREFWand1989" class="citation conference cs1">Wand, Mitchell (June 1989). "Type inference for record concatenation and multiple inheritance". <i>Proceedings. Fourth Annual Symposium on Logic in Computer Science</i>. pp. <span class="nowrap">92–</span>97. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1109%2FLICS.1989.39162">10.1109/LICS.1989.39162</a>.</cite></span>
</li>
<li id="cite_note-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-3">^</a></b></span> <span class="reference-text">
<cite id="CITEREFWand1991" class="citation journal cs1">Wand, Mitchell (1991). "Type inference for record concatenation and multiple inheritance". <i>Information and Computation</i>. <b>93</b> (Selections from 1989 IEEE Symposium on Logic in Computer Science): <span class="nowrap">1–</span>15. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1016%2F0890-5401%2891%2990050-C">10.1016/0890-5401(91)90050-C</a>. <a href="ISSN_(identifier)" class="mw-redirect" title="ISSN (identifier)">ISSN</a> <a rel="nofollow" class="external text" href="https://search.worldcat.org/issn/0890-5401">0890-5401</a>.</cite></span>
</li>
</ol></div></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2024-10-30" href="https://en.wikipedia.org/wiki/?title=Row_polymorphism&oldid=1254316568">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>
</body></html>